<%@page import="multiface.web.Util"%>
<%@page import="multiface.kooper.jpa.*"%>
<%@page import="javax.persistence.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("KooperPU");
    EntityManager em = emf.createEntityManager();
    User us = (User) session.getAttribute("user");
    User u = em.find(User.class, us.getId());
    em.refresh(u);
%>
<html>
    <jsp:include flush="true" page="import.jsp"></jsp:include>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Question</title>
    </head>
    <body>
        <jsp:include flush="true" page="header.jsp"></jsp:include>
        <div id="container">
            <div id="wrapper">
                <jsp:include flush="true" page="left.jsp"></jsp:include>
                <div id="center" class="center tiny">
                    <%
                        int c = 0;
                        for (Question p : u.getQuestionList()) {
                            c++;
                            out.print("<div class=\"post\">");
                            out.print("<div class=\"post-title\">" + c + ". <a href=\"javascript:answer_of_post('" + p.getId() + "');\">" + p.getText() + "</a></div>");
                            out.print("<div class=\"post-subtitle\">" + Util.getData(p.getDate()) + "</div>");
                            for (Answer a : p.getAnswerList()) {
                                String img = "";
                                if (a.getUser().getImageTh() != null) {
                                    img = "<img class=\"image_tiny\" alt=\"image user\" src=\"../GetImageServlet?uid=" + a.getUser().getId() + "\"/> ";
                                } else {
                                    img = "<img class=\"image_tiny\" alt=\"image user\" src=\"../engine/img/avatar.png\"/> ";
                                }
                                out.print("<div class=\"pt_" + p.getId() + " post-user hidden\">" + img + a.getUser().getName() + " " + a.getUser().getSurname() + " - " + Util.getData(a.getData()).toString() + "</div>");
                                out.print("<div class=\"pt_" + p.getId() + " post-text hidden\">" + a.getText() + "</div>");

                            }
                    %><div class="pt_<%=p.getId()%> post-send hidden"><jsp:include flush="true" page="send.jsp"></jsp:include></div><%

                            out.print("</div>");
                        }

                        em.close();
                        emf.close();
                    %>
                </div>
            </div>
        </div>
        <jsp:include flush="true" page="footer.jsp"></jsp:include>
    </body>
</html>


